package com.specialized.common.core.domain;

import java.util.ArrayList;
import java.util.List;


/**
 * @Author：djh
 * @Package：com.specialized.common.core.domain
 * @Project：Specialized-Cloud
 * @name：Subject
 * @Date：2024/7/21 15:15
 */
public class Subject {

    private List<Observer> observers= new ArrayList<Observer>();

    private Integer state;

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
        this.notifyAllObservers();
    }

    public void attach(Observer observer){
        observers.add(observer);

    }

    public void notifyAllObservers(){
        for (Observer observer : observers) {
            observer.update();
        }
    }
}
